package com.gtw.modules.api.controller;

import com.gtw.common.annotation.LoginUserApi;
import com.gtw.common.utils.R;
import com.gtw.modules.api.service.TbUserBankCardService;
import com.gtw.modules.entity.TbUser;
import com.gtw.modules.entity.TbUserBankCard;
import com.gtw.utils.PayType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/** 用户钱包信息
 * Created by wuye on 2018/4/17.
 */
@RestController
@RequestMapping("/api/userbankcard")
public class TbUserBankCardController {

    @Autowired
    private TbUserBankCardService tbUserBankCardService;

    /**
     *
     * @return
     */
    @RequestMapping("/list")
    public R list(@LoginUserApi TbUser tbUser){
        List<TbUserBankCard> list =  tbUserBankCardService.foundByIdBankCard2(tbUser.getUuid());
        return R.ok().put("data",list);
    }


    /**
     * 添加用户银行卡信息
     * @return
     */
    @RequestMapping("/save")
    public R save(@RequestParam("bankcard")String bankcard,@RequestParam("name")String name ,String bankType,@LoginUserApi TbUser tbUser){
        TbUserBankCard tbUserBankCard = new TbUserBankCard();
        tbUserBankCard.setBankcard(bankcard);
        tbUserBankCard.setUid(tbUser.getUuid());
        tbUserBankCard.setCreatetime(new Date());
        tbUserBankCard.setCardusername(name);
        tbUserBankCard.setPhone(tbUser.getMobile());
        tbUserBankCard.setPaytype(PayType.CT_UN.getName());
        tbUserBankCard.setBankType(bankType);
        tbUserBankCardService.insert(tbUserBankCard);
        return R.ok();
    }

}
